<?php
namespace app\home\model;
use think\Model;
use think\Db;

class PatrolLineM extends Model{
    protected $table = 'patrol_line'; // 设置当前模型对应的完整数据表名称
    protected $pk = 'LineID';

    // 模型初始化
    protected static function init()
    {
        //TODO:初始化内容
    }

    public function listP($page,$size){

        $m = new PatrolLineM();

        $total = PatrolLineM::count();
        $list = Db::view('patrol_line c', '*')
            ->view('sys_user u', 'UserName as cuser', 'c.Creator=u.UserId', 'left')
            ->view('sys_user u2', 'UserName as upuser', 'c.Updater=u2.UserId', 'left')
            ->page($page,$size)
            ->order('UpdateTime desc,CreateTime desc')
            ->select();
/*        $list =$m->where($where)
            ->page($page,$size)
            ->order('CreateTime desc')
            ->select();*/
        // 过滤post数组中的非数据表字段数据
        return [
            'total'=>$total,
            'page'=>$page,
            'size'=>$size,
            'list'=>$list
        ];
    }
    public function all(){
        $res = PatrolLineM::select();
        // 过滤post数组中的非数据表字段数据
        return $res;
    }

    public function addOne(){
        $data = input('post.');
        $data['Creator'] = session('user.UserId');
        $data['Updater'] = session('user.UserId');
        $data['UpdateTime'] = date('Y-m-d H:i:s', time());
        $m = new PatrolLineM($data);
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->save();
    }

    public function editOne(){
        $data = input('post.');
        $data['Updater'] = session('user.UserId');
        $data['UpdateTime'] = date('Y-m-d H:i:s', time());
        $m = new PatrolLineM();
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->update($data);
//  条件修改      return $sup->allowField(true)->save(input('post.'),['c_id' => input('post.id')]);
    }
    public function delOne($id){
        return PatrolLineM::destroy($id);
// 支持批量删除多个数据 User::destroy('1,2,3');
// 或者 User::destroy([1,2,3]);
    }


}